import os
import io
import base64
import asyncio
import logging
import json

from typing import Optional, Union
from wechaty_puppet import FileBox
from wechaty import Wechaty, Contact, MessageType
from wechaty.user import Message, Room

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(filename)s <%(funcName)s> %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S',
)

log = logging.getLogger(__name__)


async def message(msg: Message) -> None:
    """back on message"""
    text = await msg.mention_text()
    await msg.say(text)

bot: Optional[Wechaty] = None


async def main() -> None:
    """doc"""
    # pylint: disable=W0603
    global bot
    bot = Wechaty().on('message', message)
    await bot.start()


asyncio.run(main())
